package com.jz.community.moduleshopping.utils;

import android.content.Context;

import com.jz.community.basecomm.base.BaseSP;
import com.jz.community.basecomm.bean.LoginBaseInfo;
import com.jz.community.basecomm.utils.BaseSpUtils;
import com.jz.community.basecomm.utils.Preconditions;

/**
 * Created by Tony.Fan on 2018/6/21 17:10
 */
public class SpUtils extends BaseSP {

    @Override
    public String getModelPreferenceFIleName() {
        return "address_msg";
    }

    private static SpUtils spUtils = new SpUtils();

    public static SpUtils getInstance() {
        return spUtils;
    }


    /**
     * 获取自提收货人
     *
     * @param context
     * @return
     */
    public String getConsigneeName(Context context) {
        String consigneeName = getString(context, "consigneeName");
        if (!Preconditions.isNullOrEmpty(consigneeName)) {
            return consigneeName;
        } else {
            LoginBaseInfo loginBaseInfo = BaseSpUtils.getInstance().getUserBaseInfo(context);
            if (!Preconditions.isNullOrEmpty(loginBaseInfo)) {
                return loginBaseInfo.getName();
            } else {
                return "";
            }
        }
    }

    /**
     * 保持自提收货人
     *
     * @param context
     * @param consigneeName
     */
    public void setConsigneeName(Context context, String consigneeName) {
        putString(context, "consigneeName", consigneeName);
    }

    /**
     * 获取自提收货人电话
     *
     * @param context
     * @return
     */
    public String getConsigneePhone(Context context) {
        String consigneePhone = getString(context, "consigneePhone");
        if (!Preconditions.isNullOrEmpty(consigneePhone)) {
            return consigneePhone;
        } else {
            LoginBaseInfo loginBaseInfo = BaseSpUtils.getInstance().getUserBaseInfo(context);
            if (!Preconditions.isNullOrEmpty(loginBaseInfo)) {
                return loginBaseInfo.getMobi();
            } else {
                return "";
            }
        }
    }

    /**
     * 保持自提收货人电话
     *
     * @param context
     * @param consigneeName
     */
    public void setConsigneePhone(Context context, String consigneeName) {
        putString(context, "consigneePhone", consigneeName);
    }
}
